package com.kbtx.studyBrowser.URLsupport;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;

/* loaded from: classes2.dex */
public class GetPostUtil {
    public static String sendGet(String url, String params) {
        return sendGet(url, params, "utf-8");
    }

    public static String sendGet(String url, String params, String codeType) {
        BufferedReader in;
        StringBuilder result = new StringBuilder();
        try {
            URLConnection conn = new URL(url + "?" + params).openConnection();
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36");
            conn.connect();
            conn.getHeaderFields();
            in = new BufferedReader(new InputStreamReader(conn.getInputStream(), codeType));
            while (true) {
                String line = in.readLine();
                if (line == null) {
                    break;
                }
                result.append(line);
                result.append("\n");
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return result.toString();
    }

    public static String sendPost(String url, String params) {
        return sendPost(url, params, "utf-8");
    }

    public static String sendPost(String url, String params, String codeType) {
        BufferedReader in;
        PrintWriter out;
        StringBuilder result = new StringBuilder();
        try{
            URLConnection conn = new URL(url).openConnection();
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            out = new PrintWriter(conn.getOutputStream());
            out.print(params);
            out.flush();
            in = new BufferedReader(new InputStreamReader(conn.getInputStream(), codeType));
            while (true) {
                String line = in.readLine();
                if (line == null) {
                    break;
                }
                result.append(line);
                result.append("\n");
            }
            in.close();
            out.close();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result.toString();
    }
}
